﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace GDI_AnalysisComponents
{

    class Common
    {
    }

    public class Const
    {
        public const float PI = 3.1416f;
        public const int PickRadius = 3;
    }

    public enum MouseEventMode
    {
        Normal, MoveComponent, LinkLine,LinkLineMove, TransformShape, AddComponent, SelectComponent,SelLine
    }


    public enum TransformShapeMode
    {
        Normal,TransformShape_LU, TransformShape_LD, TransformShape_RU, TransformShape_RD
    }


    [Serializable()]
    public class Module
    {
        //判断拾取点是否位于包围矩形中
        public bool InBox(GBox aBox, PointF aPos)
        {
            if (aPos.X > aBox.minX && aPos.Y > aBox.minY && aPos.X < aBox.maxX && aPos.Y < aBox.maxY)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        //计算点与点之间的距离
        public float DistPtoP(PointF p1, PointF p2)
        {
            float dx, dy;
            dx = p2.X - p1.X;
            dy = p2.Y - p1.Y;
            float dist = (float)(Math.Sqrt((dx * dx) + (dy * dy)));
            return dist;
        }

        //计算点间连线与X轴正向之间的夹角
        public float GetAngle(PointF p1, PointF p2)
        {
            float tansita, sita, dx;
            float angle = 0;
            dx = Math.Abs(p2.X - p1.X);
            if (p2.X == p1.X) { dx = 0.0001f; }
            tansita = Math.Abs(p2.Y - p1.Y) / dx;
            sita = (float)(Math.Atan(tansita));
            //如果终点横坐标大于、等于起点横坐标，并且终点纵坐标大于、等于起点纵坐标
            if (p2.X >= p1.X && p2.Y >= p1.Y) { angle = sita; }
            //如果终点横坐标小于、等于起点横坐标，并且终点纵坐标大于、等于起点纵坐标
            if (p2.X <= p1.X && p2.Y >= p1.Y) { angle = Const.PI - sita; }
            //如果终点横坐标小于、等于起点横坐标，并且终点纵坐标小于、等于起点纵坐标
            if (p2.X <= p1.X && p2.Y <= p1.Y) { angle = Const.PI + sita; }
            //如果终点横坐标大于、等于起点横坐标，并且终点纵坐标小于、等于起点纵坐标
            if (p2.X >= p1.X && p2.Y <= p1.Y) { angle = Const.PI * 2 - sita; }

            return angle;
        }
    }
}
